﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NFinal.Advanced;

namespace WebApplication1.DDD.Web.Default.login
{
    public class regAction  : Controller
	{
		#if (!AspNET && !MicrosoftOwin && !NFinalOwin)
		public regAction(HttpContext context):base(context){}
		public regAction(Microsoft.Owin.IOwinContext context):base(context){}
		public regAction(NFinal.Owin.HtmlWriter writer,NFinal.Owin.Request request):base(writer,request){}
		#endif
		#if AspNET
		public regAction(HttpContext context):base(context){}
		#endif
		#if MicrosoftOwin
		public regAction(Microsoft.Owin.IOwinContext context):base(context){}
		#endif
		#if NFinalOwin
		public regAction(string fileName, NFinal.Owin.Request request, NFinal.CompressMode compressMode) :base(fileName,request,compressMode){}
		public regAction(System.IO.Stream stream,NFinal.Owin.Request request, NFinal.CompressMode compressMode) : base(stream,request,compressMode) {}
		public regAction(System.Collections.Generic.IDictionary<string, object> enviroment, NFinal.Owin.Request request, NFinal.CompressMode compressMode):base(enviroment,request,compressMode){}
		#endif
		public regAction(Controller controller):base(controller){}
        
        
        public void reg(string name,string pwd)
        {
            
var con = new System.Data.SQLite.SQLiteConnection(NFinal.Config.ConfigurationManager.ConnectionStrings["Common"].ConnectionString);
con.Open();

            
#region	var id; 插入并返回ID
			var __reg_id_command__ = new System.Data.SQLite.SQLiteCommand("insert into users(name,pwd) values(@name,@pwd);select last_insert_rowid();", con);
						var __reg_id_parameters__=new System.Data.SQLite.SQLiteParameter[2];
			
			__reg_id_parameters__[0] = new System.Data.SQLite.SQLiteParameter("@name",System.Data.DbType.String);
			__reg_id_parameters__[0].Value = name.WithDBNull();
			__reg_id_parameters__[1] = new System.Data.SQLite.SQLiteParameter("@pwd",System.Data.DbType.String);
			__reg_id_parameters__[1].Value = pwd.WithDBNull();
						__reg_id_command__.Parameters.AddRange(__reg_id_parameters__);
							var id = __reg_id_command__.ExecuteScalar().AsVar();
			__reg_id_command__.Dispose();
			#endregion
			
            con.Close();
            AjaxReturn(id>0);
        }
    }
}